package com.example.chat.mapper;

import com.example.chat.entity.ChatSession;
import com.example.chat.model.FileChatDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/7/6 15:33
 **/
@Mapper
public interface ChatSessionMapper {
    @Insert("""
insert into chat_session (chat_id, chat_name, type, user_id, create_time, update_time, operator_id, is_delete) 
values (#{chatId}, #{chatName}, #{type}, #{userId}, now(), now(), null, 0)
""")
    void insertChatSession(ChatSession chatSession);

    @Select("""
select * from chat_session where chat_id = #{chatId}
""")
    ChatSession getChatSessionByChatId(String chatId);

    @Select("""
select * from chat_session where user_id = #{userId} and type = #{type} order by update_time desc
""")
    List<ChatSession> getCHatSessionsByUserId(@Param("userId") String userId, @Param("type") String type);

    @Update("""
update chat_session set update_time = now() where chat_id = #{chatId};
""")
    void updateChatTime(String chatId);

    @Select("""
select *, cs.chat_name as filename 
from chat_session cs left join file_upload fu on cs.chat_name = fu.original_name
where cs.chat_id = #{chatId}
""")
    FileChatDO getFileChatInfo(String chatId);
}
